package org.gap.wizards.world.actions;

import java.util.List;

import org.gap.wizards.items.Item;
import org.gap.wizards.pc.PlayerCharacter;
import org.gap.wizards.views.InventorySelectionView;
import org.gap.wizards.views.MessageOutput;
import org.gap.wizards.world.WorldAction;

public class ApplyItemAction implements WorldAction {
	
	private final PlayerCharacter pc;
	private final MessageOutput output;
	private final InventorySelectionView equipmentSelection;

	public ApplyItemAction(PlayerCharacter pc, MessageOutput output, InventorySelectionView equipmentSelection) {
		this.pc = pc;
		this.output = output;
		this.equipmentSelection = equipmentSelection;
	}
	
	@Override
	public void perform() {
//		if (pc.getInventory().allItems().isEmpty()) {
//			output.addMessage("No items to apply");
//			return;
//		}
		output.addMessage("Select an item to use?");
		output.draw();
		equipmentSelection.setItems(pc.getInventory().allItems());
		List<Item> selection = equipmentSelection.getSelection();
		for (Item each : selection) {
			each.applyAffectsOn(pc);
			output.addMessage("You use " + each.getName());
			if (each.isConsumed()) {
				pc.getInventory().removeItem(each);
			}
		}
	}
}
